<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRefundOrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('refund_order', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('sn')->comment('商户退款号');
            $table->string('refund_sn')->nullable()->comment('支付平台退款号');
            $table->bigInteger('user_id', false, true)->comment('用户ID');
            $table->bigInteger('order_id', false, true)->comment('订单ID');
            $table->bigInteger('pay_order_id', false, true)->comment('支付订单表ID');
            $table->string('pay_order_sn', false, true)->comment('支付订单表支付号');
            $table->decimal('price', 10, 2)->comment('退款金额');
            $table->integer('time', false, true)->comment('退款时间');
            $table->integer('success_time', false, true)->nullable()->comment('退款成功时间 时间戳');
            $table->tinyInteger('status', false, true)->comment('状态 0-待退款 1-退款中 2-成功');
            $table->tinyInteger('type', false, true)->comment('类型 1-乘客订单取消 2-服务结束退款');
            $table->tinyInteger('refund_type', false, true)->nullable()->comment('退款方式 1-微信');
            $table->text('refund_data')->nullable()->comment('支付平台退款回调返回数据');
            $table->timestamps();

            $table->index([
                'user_id', 'order_id', 'pay_order_id'
            ]);
        });
        \DB::statement("ALTER TABLE `pay_order` comment '退款订单表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('refund_order');
    }
}
